/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package systole.view.wizard.analysis;

import systole.domain.signals.RawSignal;
import systole.view.wizard.PageController;
import systole.view.wizard.WizardResult;

/**
 *
 * @author jmj
 */
public class FirstPageController extends PageController {

    public static final String KEY = "FIRST_PAGE";
    private JPnlFirstPage page = null;
    private RawSignal preSelected;
    private String path;

    /**
     * 
     * @param preSelected
     * @param path
     */
    public FirstPageController(RawSignal preSelected, String path) {
        super();
        this.path = path;
        this.preSelected = preSelected;
    }

    @Override
    public String validatePage() {
        return this.getPage().validateConditions();
    }

    /**
     * @return the page
     */
    public JPnlFirstPage getPage() {
        if (this.page == null) {
            this.page = new JPnlFirstPage();
            if ((this.path != null) && (this.preSelected != null)) {
                this.page.setSelectedRawSignal(this.preSelected, this.path);
            }
        }
        return page;
    }

    @Override
    public boolean hasNext() {
        return true;
    }

    @Override
    public boolean hasLast() {
        return false;
    }

    @Override
    public String getKey() {
        return KEY;
    }

    @Override
    public boolean pageInitialized() {
        return this.page != null;
    }

    @Override
    public WizardResult loadResult(WizardResult result) {
        result.putObjet("signal", this.page.getFileName());
        result.putObjet("rawSignal", this.page.getRawSignal());
        result.putObjet("period", this.page.getFrequency());
        result.putObjet("date", this.page.getDate());
        result.putObjet("filename", this.page.getCurrentFile());
        result.putObjet("inverted", this.page.isInverted());
        this.page.saveSettings();
        return result;
    }
}
